home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 726-750 / 741 / rkrm_devices / rkrm_devices.lha / Resources / Allocate_Misc.c < prev    next >
C/C++ Source or Header  |  1992-09-03  |  3KB  |  97 lines

  1. /*
  2.  * Copyright (c) 1992 Commodore-Amiga, Inc.
  3.  * 
  4.  * This example is provided in electronic form by Commodore-Amiga, Inc. for 
  5.  * use with the "Amiga ROM Kernel Reference Manual: Devices", 3rd Edition, 
  6.  * published by Addison-Wesley (ISBN 0-201-56775-X).
  7.  * 
  8.  * The "Amiga ROM Kernel Reference Manual: Devices" contains additional 
  9.  * information on the correct usage of the techniques and operating system 
  10.  * functions presented in these examples.  The source and executable code 
  11.  * of these examples may only be distributed in free electronic form, via 
  12.  * bulletin board or as part of a fully non-commercial and freely 
  13.  * redistributable diskette.  Both the source and executable code (including 
  14.  * comments) must be included, without modification, in any copy.  This 
  15.  * example may not be published in printed form or distributed with any
  16.  * commercial product.  However, the programming techniques and support
  17.  * routines set forth in these examples may be used in the development
  18.  * of original executable software products for Commodore Amiga computers.
  19.  * 
  20.  * All other rights reserved.
  21.  * 
  22.  * This example is provided "as-is" and is subject to change; no
  23.  * warranties are made.  All use is at your own risk. No liability or
  24.  * responsibility is assumed.
  25.  *
  26.  *****************************************************************************
  27.  *
  28.  *
  29.  * Allocate_Misc.c
  30.  *
  31.  * Example of allocating a miscellaneous resource
  32.  * We will allocate the serial resource and wait till
  33.  * CTRL-C is pressed.  While we are waiting, the
  34.  * query_serial program should be run.  It will try
  35.  * to open the serial device and if unsuccessful, will
  36.  * return the name of the owner.  It will be us!
  37.  *
  38.  * Compile with SAS 5.10  lc -b1 -cfistq -v -y -L
  39.  *
  40.  * Run from CLI only
  41.  */
  42.  
  43. #include <exec/types.h>
  44. #include <exec/memory.h>
  45. #include <dos/dos.h>
  46. #include <resources/misc.h>
  47.  
  48. #include <clib/exec_protos.h>
  49. #include <clib/misc_protos.h>
  50.  
  51. #include <stdio.h>
  52.  
  53. #ifdef LATTICE
  54. int CXBRK(void) { return(0); }  /* Disable SAS CTRL/C handling */
  55. int chkabort(void) { return(0); }  /* really */
  56. #endif
  57.  
  58. struct Library *MiscBase = NULL;
  59.  
  60. void main(int argc, char **argv)
  61. {
  62.  
  63. UBYTE *owner = NULL;       /* owner of misc resource */
  64.  
  65. if (!(MiscBase= (struct Library *)OpenResource(MISCNAME)))
  66.     printf("Cannot open %s\n",MISCNAME);
  67. else
  68.    {
  69.     /* Allocate both pieces of the serial hardware */
  70.     if ((owner = AllocMiscResource(MR_SERIALPORT,"Serial Port Hog")) == NULL)
  71.         {
  72.         if ((owner = AllocMiscResource(MR_SERIALBITS,"Serial Port Hog")) == NULL)
  73.             {
  74.             /* Wait for CTRL-C to be pressed */
  75.             printf("\nWaiting for CTRL-C...\n");
  76.             Wait(SIGBREAKF_CTRL_C);
  77.  
  78.             /* We're back */
  79.  
  80.             /* Deallocate the serial port register */
  81.             FreeMiscResource(MR_SERIALBITS);
  82.             }
  83.         else
  84.             printf("\nUnable to allocate MR_SERIALBITS because %s owns it\n",owner);
  85.  
  86.         /* Deallocate the serial port */
  87.         FreeMiscResource(MR_SERIALPORT);
  88.        }
  89.     else
  90.        printf("\nUnable to allocate MR_SERIALPORT because %s owns it\n",owner);
  91.    }
  92. }
  93.  
  94.  
  95.  
  96.  
  97.